<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ page import="com.pmsco.pms.core.constant.PmsConstant"%>
<%@ page import="com.pmsco.pms.util.BundleUtil"%>
<%@ include file="/WEB-INF/import/tagLibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<%@ include file="/WEB-INF/import/jqGridCssAndJavascript.jsp" %>
</head>
<body class="pmsMainBody">
	<table class="pmsMainTable">
		<tr class="pmsMainTableWrapperTd">
			<td>
				<table id="menuList">
					<tr>
						<td>menu data list will be show here</td>
					</tr>
				</table>
				<div id="menuPager"></div>
			</td>
		</tr>
		<tr>
			<td>
				<table align="center">
					<tr>
						<td>
							<button id="deleteSelectedMenu" class="tableFormButton" onclick="deleteSelectedMenuItems()"><spring:message code="button.deleteSelected"/></button>
							<button id="createMenu" class="tableFormButton" onclick="submitAction('<%=PmsConstant.createMenu_JspUrl%>')"><spring:message code="button.create"/></button>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</body>
<script type="text/javascript">
	$("#menuList").jqGrid({
		url: '<%=PmsConstant.listMenuData_JspUrl%>',
		datatype: "json",
		autowidth: true,
		height: 500,
		jsonReader : { 
		      root: "rows", 
		      page: "page", 
		      total: "total", 
		      records: "records", 
		      repeatitems: false, 
		      cell: "", 
		      id: "name",
		      userdata: ""
		   },
		colNames: [
        	'<%=BundleUtil.getInstance().getKey("menu.name")%>',
        	'<%=BundleUtil.getInstance().getKey("menu.url")%>',
        	'<%=BundleUtil.getInstance().getKey("menu.isLogonRequired")%>',
        	'<%=BundleUtil.getInstance().getKey("menu.isTopLevel")%>',
        	'<%=BundleUtil.getInstance().getKey("menu.parent")%>',
        	'<%=BundleUtil.getInstance().getKey("menu.orderId")%>',
        	'<%=BundleUtil.getInstance().getKey("link.delete")%>'
       	],
		colModel: [
		    {name: 'name', index: 'name', width: 20, sorttype: "string"},
		    {name: 'url', index: 'url', width: 30, sorttype: "string"},
		    {name: 'isLogonRequired', index: 'isLogonRequired', width: 10, sorttype: "string"},
		    {name: 'isTopLevel', index: 'isTopLevel', width: 10, sorttype: "string"},
		    {name: 'parent', index: 'parent', width: 20, sorttype: "string"},
		    {name: 'orderId', index: 'orderId', width: 10, sorttype: "long"},
		    {name: 'selected', width: 2, edittype: 'checkbox', formatter: "checkbox", editoptions: { value:"True:False" }, editable:true, formatoptions: {disabled : false}}
	    ],
	    rowNum:10, 
	    rowList:[10,20,30],
	    viewrecords: true,
	    pager: '#menuPager',
	    sortorder: "desc",
	    sortname: 'name',
	    onSelectRow: function(rowid) {
	    	submitAction("<%=PmsConstant.editMenu_JspUrl%>" + "?menuName=" + rowid);
	    }
	});

	//hide caption bar. no need this bar
	jQuery("#menuList").jqGrid('navGrid','#menuPager', {edit:false, add:false, del:false});
	$("#menuList > .ui-jqgrid-titlebar").hide();
	$("#createMenu").button();
	$("#deleteSelectedMenu").button();
	
	function deleteSelectedMenuItems() {
		var selectedMenuNames = [];
		$("#menuList td[aria-describedby='menuList_selected'] input").each(function () {
				if($(this).attr('checked') == 'checked')
					selectedMenuNames.push($(this).parent('td').parent('tr').attr('id'));
		});
		submitAction("<%=PmsConstant.deleteMenu_JspUrl%>" + "?selectedMenuNames=" + selectedMenuNames);
	}
</script>
</html>